/**
 * 
 */
package classexercise;

import java.text.DecimalFormat;

/**
 * @author qingke
 *
 */
public class MyTime {
	
	private int hour=0;
	private int minute=0;
	private int second=0;
	
	public MyTime(){}
	public MyTime(int hour,int minute,int second){
		this.hour=hour;
		this.minute=minute;
		this.second=second;
	}
	public void setTime(int hour,int minute,int second){
		 this.hour=hour;
		 this.minute=minute;
		 this.second=second;
	}
	public int getHour() {
		return hour;
	}
	public void setHour(int hour) {
		this.hour = hour;
	}
	public int getMinute() {
		return minute;
	}
	public void setMinute(int minute) {
		this.minute = minute;
	}
	public int getSecond() {
		return second;
	}
	public void setSecond(int second) {
		this.second = second;
	}
	public String toString(){
		  DecimalFormat h =new DecimalFormat("##00");
		  return h.format(hour)+":"+h.format(minute)+":"+h.format(second);
	}
	public MyTime nextSecond(){
	       second ++;
	       if(second==60){
	    	   minute +=1;
	    	   second=0;
	       }
	       if(minute==60){
	    	   hour+=1;
	           minute=0; 			   
	       }if(hour==24){
	    	   hour=0;
	       }
	       return this;
	}
	public MyTime nextMinute(){
		    minute++;
		  if(minute==60){
	    	   hour+=1;
	           minute=0; 			   
	       }if(hour==24){
	    	   hour=0;
	       }
	       return this;
	}
	public MyTime nextHour(){
		   hour++;
		   if(hour==24){
	    	   hour=0;
	       }
	       return this;		   
	}
	public MyTime previousSecond(){
		    second-=1;
		    if(second==-1)
		    { 
		    	second=59;
		    	minute-=1;
		    	
		    }
		    if(minute==-1){
		    	minute =59;
		    	hour -=1; 	
		    }
		    if(hour==-1){
		    	hour=23;
		    }
		    return this;
	}
	public MyTime previousMinute(){
		    minute-=1;
		   if(minute==-1){
			    minute =59;
		    	hour-=1;    	
		    }
		    if(hour==0){
		    	hour=23;
		    }
		    return this;
	}
	public MyTime previousHour(){
		   hour-=1;
		    if(hour==-1){
		    	hour=23;
		    }
		    return this;	   
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
